export function getFlatArrDataById(data= [], keyId, id) {
  return (data || []).find(d => d[keyId] === id) || {}
}

export function getLeafNodes(data) {
  const arr = []
  for(let item of data) {
    const subList = (item || {}).subList || []
    if(subList.length === 0) {
      arr.push(item)
    } else {
      getLeafNodes(subList)
    }
  }

  return arr;
}


export function getTargetSubObj(data, key = 'subList',  i = 0) {
  if(!Array.isArray(data)) {
    return null
  }
  let arr = data;
  let targetObj = arr[i]
  while (Array.isArray(targetObj[key])) {
    arr = targetObj[key]
    targetObj = arr[i]
  }
  return targetObj
}
